﻿using Janus.Mes.DTO;
using Janus.Mes.VO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.UI;

namespace Janus.Mes.WebClient.Areas.System.Controllers.Rolers
{
    public class RolersController : BaseController
    {

        public ActionResult Index(FormCollection collection)
        {
            return View(GetList(collection));
        }

        //
        // GET: /Roles/Default/Details/5

        public ActionResult Details(long id)
        {
            return View();
        }

        //
        // GET: /Roles/Default/Create

        public ActionResult Create(string id, string code)
        {
            RolersVO model = new RolersVO();
            if (!string.IsNullOrEmpty(id) && string.IsNullOrEmpty(Request["action"]))
            {
                //model = rolersService.GetByID(id);
            }
            ViewData["code"] = code;
            ViewData["Modules"] = HelperCommon.GetModulesFromXML();// moduleService.FindAll();
            return View(model);
        }

        //
        // POST: /Roles/Default/Create
        [HttpPost]
        public string Create(FormCollection form)
        {
            try
            {
                RolersVO model = new RolersVO();
                //base.SetModel<RolersDTO>(form, model);
                var retult = true;
                //retult = rolersService.Save(model);
                if (retult)
                {
                    ajaxStr = base.AjaxResultSucess;
                }
                else
                {
                    ajaxStr = base.AjaxResultFail;
                }
            }
            catch (Exception ex)
            {
                base.ExceptionHand(ex);
                ajaxStr = base.AjaxResultFail;
            }
            return "{" + ajaxStr + "}";
        }

        [HttpPost]
        public string Delete(string id)
        {
            try
            {
                var result = true;
                //result= rolersService.DeleteByID(id) > 0
                if (result)
                {
                    ajaxStr = base.AjaxDeleteSucess;
                }
                else
                {
                    ajaxStr = base.AjaxResultFail;
                }
            }
            catch (Exception ex)
            {
                ExceptionHand(ex);
                ajaxStr = base.AjaxResultFail;
            }

            return "{" + ajaxStr + "}";
        }

        /// <summary>
        /// 选择角色
        /// </summary>
        /// <param name="collection"></param>
        /// <returns></returns>
        [OutputCache(Duration = 120, Location = OutputCacheLocation.Server, VaryByParam = "selected;Name")]
        public ActionResult SelectRolers(FormCollection collection)
        {
            return View(GetList(collection, true));
        }

        protected IEnumerable<RolersDTO> GetList(FormCollection collection, bool isForControl = false)
        {
            //var searchParma = new RolersDTO();
            ////获取搜索参数如分页信息与通用参数
            //searchParma = base.SearchPara<RolersDTO>(collection, searchParma);
            //searchParma.Searcher.IsPaging = false;
            //searchParma.Searcher.HasOrders.Add(new Orders("Level", iLiving.BaseEntitys.Orders.OrderType.Asc));
            //if (isForControl)
            //{
            //    searchParma.IsAdmin = true;
            //}
            //int totalCount = 0;
            //var roleList = rolersService.Paging(searchParma, out totalCount);
            ////设置分页总数
            ////base.SetRowCount<Rolers>(roleList);
            //return roleList;
            return new List<RolersDTO>();
        }
    }
}